// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueRouter from 'vue-router'
import 'element-ui/lib/theme-chalk/index.css'
import elementUI from './element/index'
import App from './App'
import routes from './router/index'
import Storage from 'vue-ls'
import store from './store/'
// 引入 axios 和 接口文件
import api from './api/api'
import http from './api/http'
import qs from 'qs'

// 挂载到 Vue 实例， 以便全局使用
Vue.prototype.$api = api;
Vue.prototype.$http = http;
Vue.prototype.$qs = qs;
Vue.config.productionTip = false;
Vue.use(elementUI);
Vue.use(Storage);
Vue.use(VueRouter);
const router = new VueRouter({
  routes,
  strict: process.env.NODE_ENV !== 'production',
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop;
      }
      return { x: 0, y: to.meta.savedPosition || 0 }
    }
  }
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
});
